Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Espresso tests for TableDisplayActivityTest #217

Open
wants to merge 2 commits into
base: upgrade-jdk11
Choose a base branch
from

Conversation

Chinex-Boroja
Copy link

PR Description:

Add Espresso tests for verifying UI elements, fragment transactions, and RecyclerView interactions in the TablesDisplayActivity

Changes Made

  • Added Test Case: testOnCreate

    • Description: Verifies that the RecyclerView is displayed when the activity is created
  • Added Test Case: testRecyclerViewItemClick

    • Description: Simulates a click on an item in the RecyclerView and verifies that the TableDisplayActivity is launched.
  • Added Test Case: testFragmentTransaction

    • Description: Adds a TableManagerFragment to the activity and verifies that it is added successfully
  • Added Test Case: testTableDetailsDisplay

    • Description: Simulates selecting a table and verifies that the details are displayed correctly.

}

@Test
public void testOnCreate() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Chinex-Boroja Typically, your tests should have more descriptive names. This will help define the scope of your test and make its purpose more apparent. You can follow a structure like given_when_then or subjectUnderTest_actionOrInput_expectedResult.



@Test
public void testFragmentTransaction() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Chinex-Boroja Manually adding the framgment here, does not fully capture the intent of testing. When you manually add the fragment, it’s almost guaranteed that it will be added, which may not provide much value in terms of testing.

The test would be more meaningful if it verified that the fragment was added as part of the actual UI flow, triggered by user interaction or lifecycle events, rather than by directly invoking the fragment transaction in the test. This way, the test would better reflect real-world scenarios and provide more meaningful insights.

If you need more clarifications, I am happy to huddle.
CC: @wbrunette what are your thoughts?

.perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));

// Verify that the appropriate activity is launched
intended(hasComponent(TableDisplayActivity.class.getName()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Chinex-Boroja From what I can see, this test is checking that when a user clicks on an item, the app attempts to start the TableDisplayActivity. However, since this test is already within the context of TableDisplayActivity, it feels a bit redundant. Could you share your thoughts on this approach and the reasoning behind it?

Typically, when you're testing within the context of an activity, you wouldn't use the same activity instance to verify actions triggered within it. It might be more effective to verify the intended behavior by confirming what the code is expected to do and validating against that.

CC: @wbrunette

}

@Test
public void testTableDetailsDisplay() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Chinex-Boroja a more descriptive name here too

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted @Lamouresparus, will make a fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants